package com.woniuxy.carlife.carlifeuserweb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.carlife.carlifecommonsweb.exception.CarlifeGlobalException;
import com.woniuxy.carlife.carlifeuserweb.entity.ChargingStationfavorites;
import com.woniuxy.carlife.carlifeuserweb.entity.Prodectfavorites;
import com.woniuxy.carlife.carlifeuserweb.mapper.ChargingStationfavoritesMapper;
import com.woniuxy.carlife.carlifeuserweb.service.ChargingStationfavoritesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.carlife.carlifeuserweb.service.StatisticsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zjq
 * @ClassName:ChargingStationfavoritesServiceImpl
 * @Description:充电站收藏
 * @date 2021/4/6 20:02
 **/

@Service
public class ChargingStationfavoritesServiceImpl extends ServiceImpl<ChargingStationfavoritesMapper, ChargingStationfavorites> implements ChargingStationfavoritesService {

    @Resource
    ChargingStationfavoritesMapper chargingStationfavoritesMapper;

    @Resource
    StatisticsService statisticsService;
    /*
     * 功能描述〈查询充电站收藏根据用户id〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/12 14:34
     * @throws
     */

    @Override
    public List<ChargingStationfavorites> findChargingStationfavoritesByUserId(Integer userId) {
        QueryWrapper<ChargingStationfavorites> chargingStationfavoritesQueryWrapper = new QueryWrapper<>();
        chargingStationfavoritesQueryWrapper.eq("user_id", userId);

        List<ChargingStationfavorites> chargingStationfavorites = chargingStationfavoritesMapper.selectList(chargingStationfavoritesQueryWrapper);

        return chargingStationfavorites == null ? null : chargingStationfavorites;
    }


    /*
     * 功能描述〈删除充电站收藏〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/14 14:55
     * @throws
     */

    @Override
    public Boolean deleteChargingStationfavoritesBytChargingStationfavoritesId(Integer tChargingStationfavoritesId) {
        int i = chargingStationfavoritesMapper.deleteById(tChargingStationfavoritesId);
        return i > 0 ? true : false;
    }


    /*
     * 功能描述〈充电桩新增〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/14 20:00
     * @throws
     */

    @Override
    public Boolean addChargingStationfavoritesBytChargingStationfavoritesId(ChargingStationfavorites chargingStationfavorites) {
        int insert = chargingStationfavoritesMapper.insert(chargingStationfavorites);
        if (insert>0){
            boolean b = statisticsService.modifyFavorites(chargingStationfavorites.getUserId());
            if (b){
                return true;
            }
        }
        return  false;
    }

    /*
     * 功能描述〈统计用户收藏充电桩〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/15 16:54
     * @throws
     */

    @Override
    public Integer chargingStationfavoritesTotalByUserId(Integer userId) {
        QueryWrapper<ChargingStationfavorites> shoppingcartQueryWrapper = new QueryWrapper<>();
        // QueryWrapper<Employee> queryWrapper2=Wrappers.<Employee>query();
        shoppingcartQueryWrapper.eq("user_id",userId);
        Integer count = chargingStationfavoritesMapper.selectCount(shoppingcartQueryWrapper);
        return count;
    }
}
